﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Collections;

/// <summary>
/// Summary description for ControlHelper
/// </summary>
public static class WebControlHelper
{
    public static void ListControlDataBind(ListControl lc, IEnumerable col, string dataValue, string dataText)
    {
        lc.DataSource = col;
        lc.DataTextField = dataText;
        lc.DataValueField = dataValue;
        lc.DataBind();
        lc.SelectedIndex = 0;
    }
    public static void ListControlDataBind(ListControl lc, IEnumerable col, string dataValue, string dataText, string selectText)
    {
        lc.DataSource = col;
        lc.DataTextField = dataText;
        lc.DataValueField = dataValue;
        lc.DataBind();
        lc.Items.Insert(0,new ListItem(selectText,"-1"));
    }

    public static void CleanTextBoxes(params TextBox[] textBoxs)
    {
        for(int i = 0; i < textBoxs.Length; i++)
        {
            textBoxs[i].Text = string.Empty;
        }
    }

    public static void ListControlSetDefault(params ListControl[] listControls)
    {
        for (int i = 0; i < listControls.Length; i++)
        {
            listControls[i].SelectedIndex = 0;
        }
    }
}
